var a = require("../../utils/qrcode.js");

Page({
    data: {
        maskHidden: !0,
        imagePath: "",
        placeholder: "baidu.com"
    },
    onLoad: function(a) {
        var e = this.setCanvasSize(), t = "http://" + this.data.placeholder;
        this.createQrCode(t, "mycanvas", e.w, e.h);
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    setCanvasSize: function() {
        var a = {};
        try {
            var e = wx.getSystemInfoSync().windowWidth / (750 / 686), t = e;
            a.w = e, a.h = t;
        } catch (a) {
            console.log("获取设备信息失败" + a);
        }
        return a;
    },
    createQrCode: function(e, t, n, o) {
        a.qrApi.draw(e, t, n, o);
        var i = this, s = setTimeout(function() {
            i.canvasToTempImage(), clearTimeout(s);
        }, 3e3);
    },
    canvasToTempImage: function() {
        var a = this;
        wx.canvasToTempFilePath({
            canvasId: "mycanvas",
            success: function(e) {
                var t = e.tempFilePath;
                console.log(t), a.setData({
                    imagePath: t
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    previewImg: function(a) {
        var e = this.data.imagePath;
        wx.previewImage({
            current: e,
            urls: [ e ]
        });
    },
    formSubmit: function(a) {
        var e = this, t = a.detail.value.url;
        t = "" == t ? "http://" + e.data.placeholder : "http://" + t, e.setData({
            maskHidden: !1
        }), wx.showToast({
            title: "生成中...",
            icon: "loading",
            duration: 2e3
        });
        var n = setTimeout(function() {
            wx.hideToast();
            var a = e.setCanvasSize();
            e.createQrCode(t, "mycanvas", a.w, a.h), e.setData({
                maskHidden: !0
            }), clearTimeout(n);
        }, 2e3);
    }
});